/**
 * 
 */
package fhq.hcmute.modernshopping.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import fhq.hcmute.modernshopping.R;

/**
 * @author: Hien Nguyen Le
 * @emai: hien.nguyenle.it@gmail.com
 * 
 */
public class ListStoreAdapter extends ArrayAdapter<Store> {
	private Context context;
	private ArrayList<Store> listStores;

	public ListStoreAdapter(Context context, ArrayList<Store> listStores) {
		super(context, R.layout.lv_item_list_stores, listStores);
		this.context = context;
		this.listStores = listStores;
	}

	public ArrayList<Store> getStores() {
		return listStores;
	}

	@Override
	public int getCount() {
		return listStores.size();
	}

	@Override
	public Store getItem(int position) {
		return listStores.get(position);
	}

	private static class ViewHolder {
		protected TextView txt_StoreID;
		protected TextView txt_StoreName;
		protected TextView txt_StoreAddress;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			rowView = inflater.inflate(R.layout.lv_item_list_stores, null);
			ViewHolder viewHolder = new ViewHolder();
			viewHolder.txt_StoreID = (TextView) rowView
					.findViewById(R.id.txt_store_id);
			viewHolder.txt_StoreName = (TextView) rowView
					.findViewById(R.id.txt_store_name);
			viewHolder.txt_StoreAddress = (TextView) rowView
					.findViewById(R.id.txt_store_address);
			rowView.setTag(viewHolder);
		}
		ViewHolder holder = (ViewHolder) rowView.getTag();

		Store store = listStores.get(position);
		holder.txt_StoreID.setText(position + 1 + "");
		holder.txt_StoreAddress.setText(store.getAddress());
		holder.txt_StoreName.setText(store.getName());
		return rowView;
	}
}
